package com.bootcamp.s2_0922.ds._0929;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: myClassCode
 * @description:
 * @author: Keyu Li
 * @create: 2021-09-29 15:57
 **/

public class Demo2_ArrayList {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();

        List<String> list2 = new ArrayList<>();


        ArrayList<User> users = new ArrayList<>();
        users.add(new User("l1",10));
        users.add(new User("l2",11));
        users.add(new User("l3",12));
        users.add(new User("l4",13));
        users.add(new User("l5",14));

        ArrayList<User> clone = ((ArrayList) users.clone());

        clone.remove(1);
        User user = clone.get(1);
        user.age = 111;

        System.out.println(clone);
        System.out.println(users);
    }
}

class User{
    String name;
    int age;

    public User(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        final StringBuffer sb = new StringBuffer("User{");
        sb.append("name='").append(name).append('\'');
        sb.append(", age=").append(age);
        sb.append('}');
        return sb.toString();
    }
}
